package com.site.util;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;


import org.apache.struts2.ServletActionContext;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class AjaxReturnSimple {
	
    public static void ajax(int status,String response){
		JSONArray json = new JSONArray();
		JSONObject obj = new JSONObject();
		HttpServletResponse res = ServletActionContext.getResponse();
		res.setContentType("text/xml;charset=utf-8");
		PrintWriter ot = null;
		try {
			ot = res.getWriter();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		obj.put("status", status);
	    obj.put("data", response);
		json.add(obj);
		ot.println(json.toString());
    }
    
    public static void ajax(String[] response){
		JSONArray json = new JSONArray();
		JSONObject obj = new JSONObject();
		HttpServletResponse res = ServletActionContext.getResponse();
		res.setContentType("text/xml;charset=utf-8");
		PrintWriter ot = null;
		try {
			ot = res.getWriter();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		for (String object : response) {
			obj.put("data", object);
		}
		json.add(obj);
		ot.println(json.toString());
    }
}
